<?php
class Form_Post extends Zend_Form 
{
    protected $_post = null;
    
    public function __construct($post = null, $options = null){
        $this->_post = $post;
        parent::__construct($options);
    }
    
    public function init()
    {
        $this->setName('post');
        $title = new Zend_Form_Element_Text('title', array('label'=>'Заголовок :'));
        $text = new Zend_Form_Element_Textarea('text', array('label'=>'Тест топика :'));
        $blogId = new Zend_Form_Element_Select('blog_id');
        $blogService = Service_Blog::getInstance();
        foreach($blogService->getAllBlogs() as $blog){
            $blogId->addMultiOption($blog->id, $blog->name);
        }
        $submit = new Zend_Form_Element_Submit('submit');
        if($this->_post === null){
            $this->setAction('/post/update/');
            $submit->setLabel('Добавить');
        } else {
            $this->setAction('/post/update/id/' . $this->_post->id);
            $submit->setLabel('Редактировать');
        }
        
        $main = new Zend_Form_Element_Checkbox('main', array('label'=>'На главной'));
        $this->addElements(array($title, $text,$main, $blogId, $submit));
        
        if($this->_post !== null){
            $this->populate($this->_post->getData()); 
        }
        
    }
}